package com.landeb.shop.huo.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.landeb.shop.R;
import com.landeb.shop.huo.bean.BeanActOrderDetail;

import java.util.List;

/**
 * Created by blade on 2016/11/26.
 */

public class ActOrderDetailGVAdapter extends BaseAdapter {

    private Context mContext;
    private List<BeanActOrderDetail.DataBean.GoodsBean> mList;
    private LayoutInflater mInflater;


    public ActOrderDetailGVAdapter(Context context, List<BeanActOrderDetail.DataBean.GoodsBean> list) {
        mContext = context;
        mList = list;
        mInflater = LayoutInflater.from(context);
    }

    @Override
    public int getCount() {
        return mList.size();
    }

    @Override
    public Object getItem(int position) {
        return mList.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {


        ViewHolder holder = null;
        if (convertView == null) {

            convertView = mInflater.inflate(R.layout.item_act_order_detail_gv, parent, false);

            holder = new ViewHolder();
            holder.mImageView = (ImageView) convertView.findViewById(R.id.iv_item_act_order_detail);
            holder.mTitle = (TextView) convertView.findViewById(R.id.tv_title_item_act_order_detail);
            holder.mPrice = (TextView) convertView.findViewById(R.id.tv_price_item_act_order_detail);
            holder.mCount = (TextView) convertView.findViewById(R.id.tv_count_item_act_order_detail);

            convertView.setTag(holder);
        } else {
            holder = (ViewHolder) convertView.getTag();
        }


        // TODO: 2016/10/15 用glide加载图片并赋值给      mImageView
        String title = mList.get(position).getName();
        holder.mTitle.setText(title);
        String price = mList.get(position).getPrice();
        holder.mPrice.setText("¥" + price);
        String count = mList.get(position).getAmount();
        holder.mCount.setText("数量：" + count);
        String picUrl = mList.get(position).getPic();
        Glide
                .with(mContext)
                .load(picUrl)
                .placeholder(R.drawable.error_pic)
                .error(R.drawable.error_pic)
                .crossFade()
                .into(holder.mImageView);


        return convertView;
    }

    private class ViewHolder {

        private ImageView mImageView; //图标
        private TextView mTitle, mCount, mPrice; //文字

    }

}
